/*  SSObjectFilter.m
 *  MESLib
 * 
 * Copyright 2003-2009 Starline Software Ltd
 * 
 * This file is part of MESLib.
 * 
 * MESLib is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MESLib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with MESLib. If not, see <http://www.gnu.org/licenses/>.
 */
//  Created by Tobias Haughton on Wed Aug 20 2003.
//
//SSObjectFilter holds the information about a user set filter and will return whether an object meets
//its requirments

#import "SSObjectFilter.h"
#import "SSEventObject.h"

@implementation SSObjectFilter

- (id)initWithIdentifier:(int)identifier type:(int)type value:(id)value
{
   if (self = [super init]) {
      filterIdentifier = identifier;
      filterType = type;
      filterValue = [value retain];
   }
   return self;
}

- (BOOL)passesFilter:(id)object
{
   switch([self filterType]) {
      case SSStartsAfterDateFilterType:
         if([object respondsToSelector:@selector(beginTime)]) {
            if([(NSCalendarDate *)[object beginTime] compare:(NSCalendarDate *)[self filterValue]] == NSOrderedDescending) {
               return YES;
            }
         }
           break; 
      case SSEndsBeforeDateFilterType:
         if([object respondsToSelector:@selector(endTime)]) {
            if([(NSCalendarDate *)[object endTime] compare:(NSCalendarDate *)[self filterValue]] == NSOrderedAscending) {
               return YES;
            }
         }
           break;
      default:
         break;
   }

   return NO;
}

- (int)filterIdentifier
{
   return filterIdentifier;
}

- (int)filterType
{
   return filterType;
}

- (id)filterValue
{
   return filterValue;
}

- (void)dealloc
{
   [filterValue release];
   [super dealloc];
}


@end
